<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
				    <template>
						<el-select v-model="startVersion" clearable placeholder="请选择">
							<el-option
							v-for="version in startVersionOptions"
							:key="version.value"
							:label="version.label"
							:value="version.value">
							</el-option>
						</el-select>
						<el-select
							v-model="endVersion"
							clearable
							collapse-tags
							style="margin-left: 20px;"
							placeholder="请选择">
							<el-option
							v-for="item in endVersionOptions"
							:key="item.value"
							:label="item.label"
							:value="item.value">
							</el-option>
						</el-select>
						<div style="width:200px;display:inline-block;padding-right:10px;padding-left:10px;">
							<el-input v-model="inputName" width="200" placeholder="请输入名称"></el-input>
						</div>
					</template>
					<el-button type="primary" @click="getUIConfigArray">查询</el-button>
					<el-button type="primary" @click="handleAdd">新增</el-button>
				</el-form-item>
			</el-form>
		</el-col>
		
		<!--列表-->
		<el-table :data="contentlist" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
            <el-table-column prop="app_VERSION" label="开始版本"width="95" sortable/>
            <el-table-column prop="end_APP_VERSION" label="结束版本" width="95"sortable/>
		    <el-table-column prop="icon_URL_5" label="选中图标" width="120" >
                 <template scope="scope">
                   	<a target="_blank" :href="scope.row.icon_URL_5" class="" style="text-align: center;display: inline-block;">
                        <img :src="scope.row.icon_URL_5" alt="" style="text-align: center; width:100%; padding-left:-20px;">
                    </a>
                 </template>
            </el-table-column>
			<el-table-column prop="title" label="名称" width="120"sortable />
			<el-table-column prop="disclaimer_URL" label="跳转链接" width="320"  >
                 <template scope="scope">
                   	<a target="_blank" :href="scope.row.disclaimer_URL" class="" style="text-align: center;display: inline-block;">
						<span style="font-size:8px">{{scope.row.disclaimer_URL}}</span>
					</a>
                 </template>
            </el-table-column>

            <el-table-column prop="action" label="响应操作"width="120" sortable/>
			</el-table-column>
			 <el-table-column prop="sequence" label="排序"width="120" sortable/>
			</el-table-column>
            <el-table-column prop="umeng_EVENT" label="友盟事件" width="200">
			</el-table-column>
	
            </el-table-column>
			<el-table-column prop="check_HIDDEN_FLAG" label="审核隐藏" width="95" sortable>
    			<template scope="scope">
                       {{scope.row.check_HIDDEN_FLAG=='1'?"已隐藏":"显示"}}
                </template>
			</el-table-column>
			<el-table-column prop="status" label="状态" sortable>
    			<template scope="scope">
                       {{scope.row.status=='1'?"已上线":"未上线"}}
                </template>
			</el-table-column>
			<el-table-column prop="remark" label="备注"width="200" sortable>
			</el-table-column>
			<el-table-column label="操作" width="200" fixed="right">
				<template scope="scope">
					<el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
					<el-button type="danger" size="small" @click="handleStatus(scope.$index, scope.row)"> {{scope.row.status=='1'?"下线":"上线"}}</el-button>
				</template>
			</el-table-column>
		</el-table>
		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="pageSize" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
		<el-dialog title="编辑" v-model="editFormVisible" :close-on-click-modal="false">
			<el-form :model="editForm" ref="editForm" >
				<el-form-item style="margin-left:0px">
					<el-row type="flex" align="middle">
						<span style="padding-left:40px">名称</span>
						<el-col :span="2" style="width: 215px;margin-left:5px;">
								<div style="width:215px;">
									<template>
										<el-input v-model="editForm.title"></el-input>
									</template>
								</div>
							</el-col>
						<span style="padding-left:10px;margin-left:25px;">排序</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
										<el-input v-model="editForm.sequence"></el-input>
									</template>
								</div>
							</el-col>
					</el-row>
				</el-form-item>


				<el-form-item>
					<el-row type="flex" align="middle">
						<span style="padding-left:40px">图标</span>
							<el-col :span="2" style="width: 450px;margin-left:5px;">
								<div style="width:450px;">
									<template>
										<el-input v-model="editForm.icon_URL_5"></el-input>
									</template>
								</div>
							</el-col>
					</el-row>
				</el-form-item>

				<el-form-item>
					<el-row type="flex" align="middle">
						<span style="padding-left:10px">跳转链接</span>
							<el-col :span="2" style="width: 450px;margin-left:5px;">
								<div style="width:450px;">
									<template>
										<el-input v-model="editForm.disclaimer_URL"></el-input>
									</template>
								</div>
							</el-col>
					</el-row>
				</el-form-item>

                <el-form-item style="margin-left:0px;">
					<el-row type="flex" align="middle"  >
					<span style="padding-left:10px">开始版本</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
										<el-input v-model="editForm.app_VERSION"></el-input>
									</template>
								</div>
							</el-col>
						<span style="padding-left:10px;margin-left:25px;">结束版本</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
										<el-input v-model="editForm.end_APP_VERSION"></el-input>
									</template>
								</div>
						</el-col>
					</el-row>
				</el-form-item>

				<el-form-item style="margin-left:0px;">
					<el-row type="flex" align="middle"  >
					<span style="padding-left:10px;margin-left:25px;">苹果审核</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
									  	<el-radio v-model="iosIsShow" label="1">隐藏</el-radio>
  										<el-radio v-model="iosIsShow" label="0">显示</el-radio>
									</template>
								</div>
						</el-col>
						<span style="padding-left:10px;margin-left:25px;">状态</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
									  	<el-radio v-model="isShow" label="1">上线</el-radio>
  										<el-radio v-model="isShow" label="0">下线</el-radio>
									</template>
								</div>
						</el-col>
					</el-row>
				</el-form-item>

				<el-form-item style="margin-left:0px;">
					<el-row type="flex" align="middle"  >
					<span style="padding-left:10px">友盟事件</span>
						<el-col :span="2" style="width: 180px;margin-left:5px;">
								<div style="width:160px;">
									<template>
										<el-input v-model="editForm.umeng_EVENT"></el-input>
									</template>
								</div>
							</el-col>
					</el-row>
				</el-form-item>

				<el-form-item>
					<el-row type="flex" align="middle">
						<span style="padding-left:40px">备注</span>
							<el-col :span="2" style="width: 450px;margin-left:5px;">
								<div style="width:450px;">
									<template>
										<el-input  type="textarea" v-model="editForm.remark"></el-input>
									</template>
								</div>
							</el-col>
					</el-row>
				</el-form-item>
				
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="addLoading">确定</el-button>
			</div>
		</el-dialog>

	</section>
</template>

<script>
	import util from '../../common/js/util'
	import {
		updateEnter,
		getEnterList,
		appEnterGetVersion

	} from '../../api/api';
	export default {
		data() {
			return {
				filters: {
					keyword: ''
                },
                addLoading:false,
				isShow:'1',
				iosIsShow:'1',
				contentlist: [],
				total: 0,
				page: 1,
				pageSize: 10,
				listLoading: false,
				sels: [], //列表选中列
				editFormVisible: false, //编辑界面是否显示
				editLoading: false,
				//编辑界面数据
				editForm: {
					
				},
				//新增界面数据
				addForm: {
				
                },
				startVersion:'',
				endVersion:'',
				startVersionOptions:[],
				endVersionOptions:[],
				inputName:'',
			    searchParams:'',
			}
		},
		methods: {
			handleStatus: function(index, row) {
				if(row.status==1){
					row.status  = 0
				}else{
					row.status  = 1
				}
				console.log('isShow',row)
				updateEnter(row).then((res) => {
					this.editLoading = false;
					this.$message({
						message: '提交成功',
						type: 'success'
					});
					
					this.editFormVisible = false;
					this.getUIConfigArray();
				});
			},
			handleCurrentChange(val) {
				this.page = val;
				this.getUIConfigArray();
				
			},
			getAppVersion(){
				console.log('getAppVersion')
				var that = this;
				appEnterGetVersion().then((res)=>{
					let result = res.data
					if (result.code == "1000") {
						that.startVersionOptions = []
						result.data.startList.map(item => {
							that.startVersionOptions.push({
								value:item,
								label:item
							})
						});
						that.endVersionOptions = []
						result.data.endList.map(item => {
							console.log('item',item)
							that.endVersionOptions.push({
								value:item+'',
								label:item+''
							})
						});
						console.log('that',that.endVersionOptions)
					}
				})
			},
			//获取用户列表
			getUIConfigArray() {
                this.listLoading = true;
                let param = Object.assign({}, {
                    page:this.page,
                    limit:this.pageSize,
					startVersion:this.startVersion,
					endVersion:this.endVersion,
					inputName:this.inputName
				});
				getEnterList(param).then((res) => {
					let result = res.data
					if (result.code == "1000") {
						this.contentlist = res.data.data.cxUiConfigV5s.map(item => {
							return Object.assign({}, item, {
                            })
						});
						this.total = res.data.data.total
						console.log(this.contentlist)
					}
					this.listLoading = false;
				});
				this.getAppVersion();
			},
		
			//显示编辑界面
			handleEdit: function(index, row) {
				this.editFormVisible = true;
				console.log("--",row);
				this.editForm = Object.assign({}, row);
				this.isShow = this.editForm.status +''
				this.iosIsShow = this.editForm.check_HIDDEN_FLAG +''
			},
			//显示新增界面
			handleAdd: function() {
				this.isShow = '0'
                this.editFormVisible = true;
                this.editForm = {}
			},
			//编辑
			editSubmit: function() {
				this.$confirm('确认提交吗？', '提示', {}).then(() => {
					this.editLoading = true;
					this.editForm.status = this.isShow
					this.editForm.check_HIDDEN_FLAG = this.iosIsShow
					console.log("添加",this.editForm)
					updateEnter(this.editForm).then((res) => {
						this.editLoading = false;
						this.$message({
							message: '提交成功',
							type: 'success'
						});
						this.editFormVisible = false;
						this.getUIConfigArray();
					});
				});
			},
	
			selsChange: function(sels) {
				this.sels = sels;
            },
            
		},
		
		mounted() {
			this.getUIConfigArray();
		}
	}
</script>

<style scoped>

</style>



